package Nisha.collections;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

class hashMapClass// implements Comparable<Object>
{
	int id;
	String name;
	public hashMapClass(int id, String name)
	{
		this.id=id;
		this.name = name;
	}
	
	@Override
	public String toString() {

		return this.id + " "+this.name;
	}
     
	@Override
	public boolean equals(Object paramObject) {
		hashMapClass temp = (hashMapClass)paramObject;
		if((this.id==(temp.id))&&(this.name.equals(temp.name))&&(this.getClass().isInstance(paramObject)))
				{
			return true;
				}
		else
			return false;
		
	}
	/*@Override
	public int compareTo(Object paramT) {		
		return id;
	}*/
	
	@Override
	public int hashCode() {
		
		return ((Integer)(this.id)).hashCode();//+ this.name.hashCode();
	}
}

public class HashMapVsTableDemo {
	
	

	public static void main(String[] args) {
		
		Map<Integer,hashMapClass> hashMapClassObjects = new HashMap<Integer,hashMapClass>();
		Hashtable<Integer,hashMapClass> hashTableClassObjects = new Hashtable<Integer,hashMapClass>();
		
		hashMapClass hashMapClassObject1 = new hashMapClass(01,"Nisha");
		hashMapClass hashMapClassObject2 = new hashMapClass(03,"Mradul");
		hashMapClass hashMapClassObject3 = new hashMapClass(03,"Mradul");
		 hashMapClassObjects.put(04, hashMapClassObject1);
		 hashMapClassObjects.put(02, hashMapClassObject2); 
		 hashMapClassObjects.put(03, hashMapClassObject3); 
		 
		 hashTableClassObjects.put(05, hashMapClassObject1);
		 hashTableClassObjects.put(04, hashMapClassObject2); 
		 hashTableClassObjects.put(03, hashMapClassObject3); 
		 
	/*	 Iterator it =(Iterator)hashMapClassObjects.keySet().iterator();
		 while(it.hasNext())
		 {
			 Map.Entry<Integer,hashMapClass> entry= (Map.Entry)it.next();
			 System.out.println(entry.getKey()+" "+entry.getValue());
		 }*/
		 
		 
		 for(Map.Entry<Integer, hashMapClass> e : hashMapClassObjects.entrySet())
		 {
			System.out.println(e.getKey());
			System.out.println(e.getValue().id+" "+e.getValue().name);
			
		 }
		 
		System.out.println(hashMapClassObjects);
		
		System.out.println(hashTableClassObjects);
		
		if(hashTableClassObjects.get(03).equals(hashTableClassObjects.get(04)))
		{
			System.out.println("True");
		}
		else
			System.out.println("False");
 
	}

}
